home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / tstacct.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  6KB  |  171 lines

  1. {$X+,V-,B-}
  2. Program tstacct; {as of 940601}
  3.  
  4. { Testprogram for the nwAcct unit / NwTP 0.5 API. (c) 1993,1994, R.Spronk }
  5.  
  6. { Tests the following nwAcct functions:
  7.  
  8.   AccountingInstalled
  9.   AddAccountingServer
  10.   DeleteAccountHolds
  11.   DeleteAccountingServer
  12.   GetAccountStatus
  13.   SetAccountStatus
  14.   SubmitAccountCharge
  15.   SubmitAccountHold
  16.   SubmitAccountNote
  17. }
  18.  
  19. uses nwBindry,nwConn,nwAcct;
  20.  
  21. CONST testObjName='TEST';
  22.  
  23. Var connId    :byte;
  24.     currServer:string;
  25.     balance,limit,holds      :Longint;
  26.     newBalance,newLimit      :LongInt;
  27.     nCharge,nCancelHoldAmount:Longint;
  28.     oldBalance,Oldholds      :LongInt;
  29.  
  30. begin
  31. writeln('Test of the accounting functions.');
  32. writeln;
  33. writeln('You have to be logged in as SUPERVISOR');
  34. writeln('User ',testObjName,' has to exists. (hardcoded in source, change if needed).');
  35. writeln;
  36. If NOT AccountingInstalled
  37.  then begin
  38.       writeln('error#:',nwAcct.result);
  39.       write('Err:Accounting isn''t installed on the current effective server:');
  40.       GetEffectiveConnectionID(ConnID);
  41.       GetFileServerName(connId,currServer);
  42.       writeln(currServer);
  43.       halt(1);
  44.       end;
  45.  
  46. AddAccountingServer('SUPERVISOR',OT_USER);
  47.  
  48.  
  49. IF GetAccountStatus(testObjName,OT_USER,balance,limit,holds)
  50.   then begin
  51.        writeln('Current account status for user ',testObjName,' :');
  52.        writeln('Balance     :',balance);
  53.        writeln('Credit Limit:',limit);
  54.        writeln('Holds       :',holds);
  55.        end
  56.   else writeln('Err: GetAccountStatus failed. error #',nwAcct.result);
  57.  
  58. writeln('Setting new account values..');
  59. newBalance:=1020304;
  60. newLimit:=123456;
  61. IF NOT SetAccountStatus(testObjName,OT_USER,newBalance,newLimit)
  62.  then writeln('Err: SetAccountStatus failed. error #',nwAcct.result);
  63.  
  64. IF GetAccountStatus(testObjName,OT_USER,balance,limit,holds)
  65.   then begin
  66.        writeln('Current account status for user ',testObjName,' :');
  67.        writeln('Balance     :',balance);
  68.        writeln('Credit Limit:',limit);
  69.        writeln('Holds       :',holds);
  70.        if (balance<>newBalance) or (newLimit<>Limit)
  71.         then writeln('Err: the new account values where not set!');
  72.        end
  73.   else writeln('Err: GetAccountStatus failed. error #',nwAcct.result);
  74.  
  75. OldBalance:=balance;
  76. nCharge:=100;
  77. nCancelHoldAmount:=0;
  78. Writeln('Submitting an account charge. charge=',ncharge,',CancelHold=',ncancelholdamount);
  79. IF NOT SubmitAccountCharge(testObjName,OT_USER,nCharge,nCancelHoldAmount,
  80.                            OT_USER,0,'no note')
  81.  then writeln('Err: SubmitAccountCharge failed. error #',nwAcct.result);
  82.  
  83. IF GetAccountStatus(testObjName,OT_USER,balance,limit,holds)
  84.   then begin
  85.        writeln('Current account status for user ',testObjName,' :');
  86.        writeln('Balance     :',balance);
  87.        writeln('Credit Limit:',limit);
  88.        writeln('Holds       :',holds);
  89.        if (balance<>(oldBalance-nCharge))
  90.         then writeln('Err: the account charge was not carried out !');
  91.        end
  92.   else writeln('Err: GetAccountStatus failed. error #',nwAcct.result);
  93.  
  94.  
  95. OldBalance:=balance;
  96. nCharge:=-200;
  97. nCancelHoldAmount:=0;
  98. Writeln('Submitting a NEGATIVE account charge. charge=',ncharge,',CancelHold=',ncancelholdamount);
  99. Writeln(' (in fact increasing the balance of the ',testObjName,' object.');
  100. IF NOT SubmitAccountCharge(testObjName,OT_USER,nCharge,nCancelHoldAmount,
  101.                            OT_USER,99,'charge! charge!')
  102.  then writeln('Err: SubmitAccountCharge failed. error #',nwAcct.result);
  103.  
  104. IF GetAccountStatus(testObjName,OT_USER,balance,limit,holds)
  105.   then begin
  106.        writeln('Current account status for user ',testObjName,' :');
  107.        writeln('Balance     :',balance);
  108.        writeln('Credit Limit:',limit);
  109.        writeln('Holds       :',holds);
  110.        if (balance<>(oldBalance-nCharge))
  111.         then writeln('Err: the account charge was not carried out !');
  112.        end
  113.   else writeln('Err: GetAccountStatus failed. error #',nwAcct.result);
  114.  
  115. OldHolds:=holds;
  116. writeln('Submit an hold in the amount of 1234');
  117. IF SubmitAccountHold(testObjName,OT_USER,1234)
  118.  then begin
  119.       GetAccountStatus(testObjName,OT_USER,balance,limit,holds);
  120.       writeln('Current account status for user ',testObjName,' :');
  121.       writeln('Balance     :',balance);
  122.       writeln('Credit Limit:',limit);
  123.       writeln('Holds       :',holds);
  124.  
  125.       if (holds<>(OldHolds+1234))
  126.         then writeln('Err: the account hold was not carried out !');
  127.       end
  128.  else writeln('Err: SubmitAccountHold failed. error #',nwAcct.result);
  129.  
  130. Writeln('Submit a charge of 1000, unhold 1234');
  131. OldHolds:=holds;
  132. nCharge:=1000;
  133. nCancelHoldAmount:=1234;
  134. IF SubmitAccountCharge(testObjName,OT_USER,nCharge,nCancelHoldAmount,
  135.                        OT_USER,99,'let''s charge a few bucks :-)')
  136.  then begin
  137.       GetAccountStatus(testObjName,OT_USER,balance,limit,holds);
  138.       writeln('Current account status for user ',testObjName,' :');
  139.       writeln('Balance     :',balance);
  140.       writeln('Credit Limit:',limit);
  141.       writeln('Holds       :',holds);
  142.  
  143.       if (holds<>(OldHolds-1234))
  144.         then writeln('Err: the account hold was not carried out !');
  145.       end
  146.  else writeln('Err: SubmitAccountHold failed. error #',nwAcct.result);
  147.  
  148. IF DeleteAccountHolds(testObjName,OT_USER)
  149.  then begin
  150.       writeln('All further holds bythis accounting server were released.');
  151.       GetAccountStatus(testObjName,OT_USER,balance,limit,holds);
  152.       writeln('Current account status for user ',testObjName,' :');
  153.       writeln('Balance     :',balance);
  154.       writeln('Credit Limit:',limit);
  155.       writeln('Holds       :',holds);
  156.       end
  157.  else writeln('Err: DeleteAccountHolds failed. error #',nwAcct.result);
  158.  
  159. IF SubmitAccountNote(testObjName,OT_USER,
  160.                      OT_USER,99,'<<TEST OF ACCOUNTNOTE>>')
  161.    then begin
  162.         writeln('Accountnote was submitted correctly.');
  163.         writeln('Please use a hexeditor and have look at \system\net$acct.dat');
  164.         writeln('to check if the accountnote was added to the file.');
  165.         end
  166.   else writeln('Err: SubmitAccountNote failed. error #',nwAcct.result);
  167.  
  168. IF NOT DeleteAccountingServer('SUPERVISOR',1)
  169.  then writeln('Err: DeleteAccountServer failed. error #',nwacct.result);
  170.  
  171. end.